#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<chrono>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
map<LL,LL>map1;
LL solve(LL p,LL a,LL n){
    LL t=0;LL sum=0;
    while(n>0){
        t=n/p;
        sum+=t;
        n/=p;
    }
    return sum/a;
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n,b;cin>>n>>b;
  for(LL i=2;i<=sqrt(b);i++){
     if(b%i==0){
        while(b%i==0){
            map1[i]++;
            b/=i;
        }
     }
  }
  if(b>1){
    map1[b]++;
  }
  LL minv=9e18;
  for(auto i:map1){
     minv=min(minv,solve(i.first,i.second,n));
  }
  cout<<minv<<"\n";
return 0;
}
